package cloud.tianai.ram.policy.core.action;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 天爱有情
 * @date 2022/3/21 15:47
 * @Description 行为
 */
@Data
@NoArgsConstructor
public class Action {
    /** 具体资源. */
    private String resource;
    /** 什么行为. */
    private String action;
    /** 描述.*/
    private String description;
    /** 扩展字段. */
    private Map<String, Object> expand;

    public void addExpand(String key, Object value) {
        if (expand == null) {
            expand = new HashMap<>(4);
        }
        expand.put(key, value);
    }

    public Map<String, Object> getExpand() {
        return expand == null ? Collections.emptyMap() : expand;
    }

    public Action(String resource, String action) {
        this.resource = resource;
        this.action = action;
    }


    public Action copy() {
        Action action = new Action();
        action.setResource(this.resource);
        action.setAction(this.action);
        action.setDescription(this.description);
        action.setExpand(new HashMap<>(expand));
        return action;
    }
}
